<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
<meta name="viewport"
      content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">

    <meta name="author" content="John Doe">





<title>k8s相关练习 | Wikiq</title>



    <link rel="icon" href="/yinghua.png">




    <!-- stylesheets list from _config.yml -->
    
    <link rel="stylesheet" href="/css/style.css">
    



    <!-- scripts list from _config.yml -->
    
    <script src="/js/script.js"></script>
    
    <script src="/js/tocbot.min.js"></script>
    



    
    
        
    


<meta name="generator" content="Hexo 5.4.2"></head>

<body>
    <script>
        // this function is used to check current theme before page loaded.
        (() => {
            const currentTheme = window.localStorage && window.localStorage.getItem('theme') || '';
            const isDark = currentTheme === 'dark';
            const pagebody = document.getElementsByTagName('body')[0]
            if (isDark) {
                pagebody.classList.add('dark-theme');
                // mobile
                document.getElementById("mobile-toggle-theme").innerText = "· Dark"
            } else {
                pagebody.classList.remove('dark-theme');
                // mobile
                document.getElementById("mobile-toggle-theme").innerText = "· Light"
            }
        })();
    </script>

    <div class="wrapper">
        <header>
    <nav class="navbar">
        <div class="container">
            <div class="navbar-header header-logo"><a href="/">Wikiq</a></div>
            <div class="menu navbar-right">
                
                    <a class="menu-item" href="/like">Like</a>
                
                    <a class="menu-item" href="/category">Categories</a>
                
                    <a class="menu-item" href="/archives">Posts</a>
                
                    <a class="menu-item" href="/about">About</a>
                
                <input id="switch_default" type="checkbox" class="switch_default">
                <label for="switch_default" class="toggleBtn"></label>
            </div>
        </div>
    </nav>

    
    <nav class="navbar-mobile" id="nav-mobile">
        <div class="container">
            <div class="navbar-header">
                <div>
                    <a href="/">Wikiq</a><a id="mobile-toggle-theme">·&nbsp;Light</a>
                </div>
                <div class="menu-toggle" onclick="mobileBtn()">&#9776; Menu</div>
            </div>
            <div class="menu" id="mobile-menu">
                
                    <a class="menu-item" href="/like">Like</a>
                
                    <a class="menu-item" href="/category">Categories</a>
                
                    <a class="menu-item" href="/archives">Posts</a>
                
                    <a class="menu-item" href="/about">About</a>
                
            </div>
        </div>
    </nav>

</header>
<script>
    var mobileBtn = function f() {
        var toggleMenu = document.getElementsByClassName("menu-toggle")[0];
        var mobileMenu = document.getElementById("mobile-menu");
        if(toggleMenu.classList.contains("active")){
           toggleMenu.classList.remove("active")
            mobileMenu.classList.remove("active")
        }else{
            toggleMenu.classList.add("active")
            mobileMenu.classList.add("active")
        }
    }
</script>
            <div class="main">
                <div class="container">
    
    
        <div class="post-toc">
    <div class="tocbot-list">
    </div>
    <div class="tocbot-list-menu">
        <a class="tocbot-toc-expand" onclick="expand_toc()">Expand all</a>
        <a onclick="go_top()">Back to top</a>
        <a onclick="go_bottom()">Go to bottom</a>
    </div>
</div>

<script>
    document.ready(
        function () {
            tocbot.init({
                tocSelector: '.tocbot-list',
                contentSelector: '.post-content',
                headingSelector: 'h1, h2, h3, h4, h5',
                collapseDepth: 1,
                orderedList: false,
                scrollSmooth: true,
            })
        }
    )

    function expand_toc() {
        var b = document.querySelector(".tocbot-toc-expand");
        tocbot.init({
            tocSelector: '.tocbot-list',
            contentSelector: '.post-content',
            headingSelector: 'h1, h2, h3, h4, h5',
            collapseDepth: 6,
            orderedList: false,
            scrollSmooth: true,
        });
        b.setAttribute("onclick", "collapse_toc()");
        b.innerHTML = "Collapse all"
    }

    function collapse_toc() {
        var b = document.querySelector(".tocbot-toc-expand");
        tocbot.init({
            tocSelector: '.tocbot-list',
            contentSelector: '.post-content',
            headingSelector: 'h1, h2, h3, h4, h5',
            collapseDepth: 1,
            orderedList: false,
            scrollSmooth: true,
        });
        b.setAttribute("onclick", "expand_toc()");
        b.innerHTML = "Expand all"
    }

    function go_top() {
        window.scrollTo(0, 0);
    }

    function go_bottom() {
        window.scrollTo(0, document.body.scrollHeight);
    }

</script>
    

    
    <article class="post-wrap">
        <header class="post-header">
            <h1 class="post-title">k8s相关练习</h1>
            
                <div class="post-meta">
                    
                        Author: <a itemprop="author" rel="author" href="/">John Doe</a>
                    

                    
                        <span class="post-time">
                        Date: <a href="#">April 16, 2022&nbsp;&nbsp;22:34:10</a>
                        </span>
                    
                    
                </div>
            
        </header>

        <div class="post-content">
            <h4 id="【题目-1】docker-compose编排部署"><a href="#【题目-1】docker-compose编排部署" class="headerlink" title="【题目-1】docker-compose编排部署"></a>【题目-1】docker-compose编排部署</h4><p>在master节点上编写/root/owncloud/docker-compose.yaml文件，具体要求如下：</p>
<p>（1）镜像：owncloud:latest；和mysql:5.6； </p>
<p>（2）端口映射：owncloud(5679:80)、mysql(3306:3306)</p>
<p>（3）MySQL root用户密码：123456；</p>
<p>完成后编排部署owncloud，并提交master节点的用户名、密码和IP到答题框。</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">version:</span> <span class="string">&quot;3.0&quot;</span></span><br><span class="line"><span class="attr">services:</span></span><br><span class="line">  <span class="attr">owncloud:</span></span><br><span class="line">    <span class="attr">image:</span> <span class="string">owncloud:latest</span></span><br><span class="line">    <span class="attr">container_name:</span> <span class="string">owncloud</span></span><br><span class="line">    <span class="attr">ports:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">&quot;5679:80&quot;</span></span><br><span class="line">    <span class="attr">depends_on:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">mysql</span></span><br><span class="line">  <span class="attr">mysql:</span></span><br><span class="line">    <span class="attr">image:</span> <span class="string">mysql:5.6</span></span><br><span class="line">    <span class="attr">container_name:</span> <span class="string">mysql</span></span><br><span class="line">    <span class="attr">environment:</span></span><br><span class="line">      <span class="attr">MYSQL_ROOT_PASSWORD:</span> <span class="number">123456</span></span><br><span class="line">    <span class="attr">ports:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">&quot;3306:3306&quot;</span></span><br></pre></td></tr></table></figure>



<h4 id="【题目0】docker-compose编排部署"><a href="#【题目0】docker-compose编排部署" class="headerlink" title="【题目0】docker-compose编排部署"></a>【题目0】docker-compose编排部署</h4><p>在master节点上编写/root/wordpress/docker-compose.yaml文件，具体要求如下：</p>
<p>（1）容器名称：wordpress；镜像：wordpress:latest；端口映射：82:80；</p>
<p>（2）容器名称：mysql；镜像：mysql:5.6； </p>
<p>（3）MySQL root用户密码：123456；</p>
<p>（4）创建数据库wordpress。</p>
<p>完成后编排部署WordPress，并提交master节点的用户名、密码和IP到答题框。</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">version:</span> <span class="string">&quot;3.0&quot;</span></span><br><span class="line"><span class="attr">services:</span></span><br><span class="line">  <span class="attr">wordpress:</span></span><br><span class="line">    <span class="attr">image:</span> <span class="string">wordpress:latest</span></span><br><span class="line">    <span class="attr">container_name:</span> <span class="string">wordpress</span></span><br><span class="line">    <span class="attr">ports:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">&quot;82:80&quot;</span></span><br><span class="line">    <span class="attr">depends_on:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">mysql</span></span><br><span class="line">    <span class="attr">restart:</span> <span class="string">always</span></span><br><span class="line">  <span class="attr">mysql:</span></span><br><span class="line">    <span class="attr">image:</span> <span class="string">mysql:5.6</span></span><br><span class="line">    <span class="attr">container_name:</span> <span class="string">mysql</span></span><br><span class="line">    <span class="attr">environment::</span></span><br><span class="line">      <span class="attr">MYSQL_ROOT_PASSWORD:</span> <span class="number">123456</span></span><br><span class="line">    <span class="attr">restart:</span> <span class="string">always</span></span><br></pre></td></tr></table></figure>



<h4 id="【题目1】容器化部署Redis"><a href="#【题目1】容器化部署Redis" class="headerlink" title="【题目1】容器化部署Redis"></a>【题目1】容器化部署Redis</h4><p>在master节点上编写/root/redis/Dockerfile文件构建chinaskill-redis:v1.1镜像，具体要求如下： </p>
<p>（1）基础镜像：centos:centos7.5.1804；</p>
<p>（2）作者：Chinaskill；</p>
<p>（3）修改配置文件中的bind 127.0.0.1为bind 0.0.0.0；</p>
<p>（4）设置Redis免密，并关闭保护模式；</p>
<p>（5）开放端口：6379；</p>
<p>（6）设置服务开机自启。</p>
<p>完成后构建镜像，并提交master节点的用户名、密码和IP到答题框。</p>
<figure class="highlight dockerfile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">FROM</span> <span class="number">192.168</span>.<span class="number">10.8</span>/library/centos:centos7.<span class="number">5.1804</span></span><br><span class="line"><span class="keyword">MAINTAINER</span> Chinaskill</span><br><span class="line"><span class="keyword">RUN</span><span class="language-bash"> <span class="built_in">rm</span> -rfv /etc/yum.repos.d/*</span></span><br><span class="line"><span class="keyword">ADD</span><span class="language-bash"> http.repo /etc/yum.repos.d/</span></span><br><span class="line"><span class="keyword">RUN</span><span class="language-bash"> yum install -y redis \ </span></span><br><span class="line">&amp;&amp; sed -i <span class="string">&#x27;s/^bind 127.0.0.1/bind\ 0\.0\.0\.0/&#x27;</span> /etc/redis.conf \</span><br><span class="line">    &amp;&amp; sed -i <span class="string">&#x27;s/protected-mode\ yes/protected-mode\ no/&#x27;</span> /etc/redis.conf</span><br><span class="line"><span class="keyword">EXPOSE</span> <span class="number">6379</span></span><br><span class="line"><span class="keyword">CMD</span><span class="language-bash"> [<span class="string">&quot;redis-server&quot;</span>, <span class="string">&quot;/etc/redis.conf&quot;</span>]</span></span><br></pre></td></tr></table></figure>

<p>http.repo</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">[centos]</span><br><span class="line">name=centos</span><br><span class="line">baseurl=http://192.168.100.10/centos</span><br><span class="line">gpgcheck=0</span><br><span class="line">[k8s]</span><br><span class="line">name=k8s</span><br><span class="line">baseurl=http://192.168.100.10/paas/kubernetes-repo/</span><br><span class="line">gpgcheck=0</span><br></pre></td></tr></table></figure>



<h4 id="【题目2】容器化部署MariaDB"><a href="#【题目2】容器化部署MariaDB" class="headerlink" title="【题目2】容器化部署MariaDB"></a>【题目2】容器化部署MariaDB</h4><p>在master节点上编写/root/mariadb/Dockerfile文件构建chinaskill-mariadb:v1.1镜像，具体要求如下： </p>
<p>（1）基础镜像：centos:centos7.5.1804；</p>
<p>（2）作者：Chinaskill；</p>
<p>（3）设置数据库密码：123456；</p>
<p>（4）创建数据库gpmall并导入数据库文件gpmall.sql；</p>
<p>（5）设置字符编码：UTF-8；</p>
<p>（6）开放端口：3306；</p>
<p>（7）设置服务开机自启。</p>
<p>完成后构建镜像，并提交master节点的用户名、密码和IP到答题框。</p>
<figure class="highlight dockerfile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">FROM</span> centos:centos7.<span class="number">5.1804</span></span><br><span class="line"><span class="keyword">MAINTAINER</span> Chinaskill</span><br><span class="line"><span class="keyword">ADD</span><span class="language-bash"> [<span class="string">&quot;http.repo&quot;</span>, <span class="string">&quot;gpmall.sql&quot;</span>, <span class="string">&quot;db_init.sh&quot;</span>, <span class="string">&quot;/root/&quot;</span>]</span></span><br><span class="line"><span class="keyword">ENV</span> MARIADB_USER=root</span><br><span class="line"><span class="keyword">ENV</span> MARIADB_PASS=<span class="number">123456</span></span><br><span class="line"><span class="keyword">RUN</span><span class="language-bash"> <span class="built_in">rm</span> -rfv /etc/yum.repos.d/* &amp;&amp; <span class="built_in">mv</span> /root/http.repo /etc/yum.repos.d/ &amp;&amp; yum install -y mariadb-server crudini &amp;&amp; crudini --<span class="built_in">set</span> /etc/my.cnf mysqld character-set-server utf8 &amp;&amp; crudini --<span class="built_in">set</span> /etc/my.cnf.d/client.cnf client default-character-set utf8</span></span><br><span class="line"><span class="keyword">RUN</span><span class="language-bash"> mysql_install_db --user=mysql &amp;&amp; <span class="built_in">sleep</span> 3</span></span><br><span class="line"><span class="keyword">RUN</span><span class="language-bash"> bash /root/db_init.sh</span></span><br><span class="line"><span class="keyword">EXPOSE</span> <span class="number">3306</span></span><br><span class="line"><span class="keyword">CMD</span><span class="language-bash"> [<span class="string">&quot;mysqld_safe&quot;</span>]</span></span><br></pre></td></tr></table></figure>

<p>http.repo</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">[centos]</span><br><span class="line">name=centos</span><br><span class="line">baseurl=http://192.168.100.10/centos</span><br><span class="line">gpgcheck=0</span><br><span class="line">[k8s]</span><br><span class="line">name=k8s</span><br><span class="line">baseurl=http://192.168.100.10/paas/kubernetes-repo/</span><br><span class="line">gpgcheck=0</span><br><span class="line">[iaas]</span><br><span class="line">name=iaas</span><br><span class="line">baseurl=http://192.168.100.10/iaas/iaas-repo</span><br><span class="line">gpgcheck=0</span><br></pre></td></tr></table></figure>

<p>db_init.sh</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">!/usr/bin/bash</span></span><br><span class="line">mysqld_safe &amp;</span><br><span class="line">sleep 3</span><br><span class="line">mysql -e &quot;use mysql; grant all privileges on *.* to &#x27;$MARIADB_USER&#x27;@&#x27;%&#x27; identified by &#x27;$MARIADB_PASS&#x27; with grant option;&quot;</span><br></pre></td></tr></table></figure>



<h4 id="【题目3】容器化部署Zookeeper"><a href="#【题目3】容器化部署Zookeeper" class="headerlink" title="【题目3】容器化部署Zookeeper"></a>【题目3】容器化部署Zookeeper</h4><p>在master节点上编写/root/zookeeper/Dockerfile文件构建chinaskill-zookeeper:v1.1镜像，具体要求如下： </p>
<p>（1）基础镜像：centos:centos7.5.1804；</p>
<p>（2）作者：Chinaskill；</p>
<p>（3）开放端口：2181；</p>
<p>（4）设置服务开机自启。</p>
<p>完成后构建镜像，使用构建的镜像运行容器myzookeeper，并提交master节点的用户名、密码和IP到答题框。</p>
<figure class="highlight dockerfile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">FROM</span> <span class="number">192.168</span>.<span class="number">10.8</span>/library/centos:centos7.<span class="number">5.1804</span></span><br><span class="line"><span class="keyword">MAINTAINER</span> Chinaskill</span><br><span class="line"><span class="keyword">ADD</span><span class="language-bash"> [<span class="string">&quot;jdk-8u77-linux-x64.tar.gz&quot;</span>, <span class="string">&quot;zookeeper-3.4.14.tar.gz&quot;</span>, <span class="string">&quot;/root/&quot;</span>]</span></span><br><span class="line"><span class="keyword">RUN</span><span class="language-bash"> <span class="built_in">mv</span> /root/jdk1.8.0_77 /usr/ &amp;&amp; <span class="built_in">mv</span> /root/zookeeper-3.4.14/conf/zoo_sample.cfg /root/zookeeper-3.4.14/conf/zoo.cfg</span></span><br><span class="line"><span class="keyword">ENV</span> JAVA_PATH=/usr/jdk1.<span class="number">8.0</span>_77</span><br><span class="line"><span class="keyword">ENV</span> PATH=$JAVA_PATH/bin:$PATH</span><br><span class="line"><span class="keyword">ENV</span> ZK_HOME=/root/zookeeper-<span class="number">3.4</span>.<span class="number">14</span></span><br><span class="line"><span class="keyword">ENV</span> PATH=$ZK_HOME/bin:$PATH</span><br><span class="line"><span class="keyword">EXPOSE</span> <span class="number">2181</span></span><br><span class="line"><span class="keyword">CMD</span><span class="language-bash"> [<span class="string">&quot;zkServer.sh&quot;</span>, <span class="string">&quot;start-foreground&quot;</span>]</span></span><br></pre></td></tr></table></figure>

<h4 id="题目A-Kafka容器化"><a href="#题目A-Kafka容器化" class="headerlink" title="[题目A]  Kafka容器化"></a><strong>[题目A]  Kafka容器化</strong></h4><figure class="highlight dockerfile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">FROM</span> centos:centos7.<span class="number">5.1804</span></span><br><span class="line"><span class="keyword">MAINTAINER</span> Chinaskill</span><br><span class="line"><span class="keyword">RUN</span><span class="language-bash"> <span class="built_in">rm</span> -rf /etc/yum.repos.d/*</span></span><br><span class="line"><span class="keyword">COPY</span><span class="language-bash"> local.repo /etc/yum.repos.d/</span></span><br><span class="line"><span class="keyword">RUN</span><span class="language-bash"> yum install -y java-1.8.0-openjdk java-1.8.0-openjdk-devel</span></span><br><span class="line"><span class="keyword">RUN</span><span class="language-bash"> <span class="built_in">mkdir</span> /opt/kafka</span></span><br><span class="line"><span class="keyword">ADD</span><span class="language-bash"> kafka_2.11-1.1.1.tgz /opt/kafka</span></span><br><span class="line"><span class="keyword">RUN</span><span class="language-bash"> sed -i -e <span class="string">&quot;s/num.partitions.*$/num.partitions=3/g&quot;</span> /opt/kafka/kafka_2.11-1.1.1/config/server.properties</span></span><br><span class="line"><span class="keyword">RUN</span><span class="language-bash"> <span class="built_in">echo</span> <span class="string">&quot;source /root/.bash_profile&quot;</span> &gt; /opt/kafka/start.sh &amp;&amp;\</span></span><br><span class="line"><span class="language-bash">    <span class="built_in">echo</span> <span class="string">&quot;cd /opt/kafka/kafka_2.11-1.1.1&quot;</span>&gt;&gt; /opt/kafka/start.sh &amp;&amp;\</span></span><br><span class="line"><span class="language-bash">    <span class="built_in">echo</span> <span class="string">&quot;sed -i &#x27;s%zookeeper.connect=.*$%zookeeper.connect=mall-zookeeper:2181%g&#x27;  /opt/kafka/kafka_2.11-1.1.1/config/server.properties&quot;</span> &gt;&gt; /opt/kafka/start.sh &amp;&amp;\</span></span><br><span class="line"><span class="language-bash">    <span class="built_in">echo</span> <span class="string">&quot;bin/kafka-server-start.sh config/server.properties&quot;</span> &gt;&gt; /opt/kafka/start.sh &amp;&amp;\</span></span><br><span class="line"><span class="language-bash">    <span class="built_in">chmod</span> a+x /opt/kafka/start.sh</span></span><br><span class="line"><span class="keyword">EXPOSE</span> <span class="number">9092</span></span><br><span class="line"><span class="keyword">ENTRYPOINT</span><span class="language-bash"> [<span class="string">&quot;sh&quot;</span>,<span class="string">&quot;/opt/kafka/start.sh&quot;</span>]</span></span><br></pre></td></tr></table></figure>

<h4 id="【题目4】安装Jenkins环境"><a href="#【题目4】安装Jenkins环境" class="headerlink" title="【题目4】安装Jenkins环境"></a>【题目4】安装Jenkins环境</h4><p>在master节点上部署Jenkins服务，具体要求如下：</p>
<p>（1）容器名称：jenkins；</p>
<p>（2）端口映射：8080:8080；</p>
<p>（3）使用root身份生成容器；</p>
<p>（4）离线安装Jenkins插件；</p>
<p>（5）设置Jenkins用户：chinaskill；密码：000000；</p>
<p>使用chinaskill用户登录Jenkins，完成后提交master节点的用户名、密码和IP到答题框。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker run -d -p 8080:8080 -u root --name jenkins 192.168.100.5/library/jenkins:2.262-centos</span><br></pre></td></tr></table></figure>

<p><a target="_blank" rel="noopener" href="https://blog.csdn.net/pansaky/article/details/80746736">https://blog.csdn.net/pansaky/article/details/80746736</a> 插件导入到docker目录重启即可</p>
<h4 id="【题目5】安装Gitlab环境"><a href="#【题目5】安装Gitlab环境" class="headerlink" title="【题目5】安装Gitlab环境"></a>【题目5】安装Gitlab环境</h4><p>在master节点上使用镜像gitlab/gitlab-ce:12.9.2-ce.0部署Gitlab服务，具体要求如下：</p>
<p>（1）容器名称：mygitlab；</p>
<p>（2）端口映射：1022:22、81:80、443:443；</p>
<p>（3）容器重启策略：always；</p>
<p>（4）设置root用户及密码；</p>
<p>（5）使用root用户登录Gitlab，密码：00000000；</p>
<p>（6）新建项目ChinaskillProject，将/opt/ChinaskillProject中的代码上传到ChinaskillProject项目中。</p>
<p>完成后提交master节点的用户名、密码和IP到答题框。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker run -d -p 1022:22 -p 81:80 -p 443:443 --name mygitlab --restart=always gitlab/gitlab-ce:12.9.2-ce.0</span><br></pre></td></tr></table></figure>



<h4 id="【题目6】配置Jenkins连接Gitlab"><a href="#【题目6】配置Jenkins连接Gitlab" class="headerlink" title="【题目6】配置Jenkins连接Gitlab"></a>【题目6】配置Jenkins连接Gitlab</h4><p>配置Jenkins连接Gitlab，具体要求如下：</p>
<p>（1）设置Outbound requests；</p>
<p>（2）生成“Access Tokens”并命名为jenkins；</p>
<p>（3）设置Jenkins取消对’/project’ end-point进行身份验证；</p>
<p>（4）测试Jenkins与Gitlab的连通性。</p>
<p>完成后提交master节点的用户名、密码和IP到答题框。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">jinkens构建时启用触发器Build when a change is pushed。。。。。</span><br><span class="line">gitlab设置创建访问令牌 名字jenkins</span><br></pre></td></tr></table></figure>



<h4 id="【题目7】Pod管理"><a href="#【题目7】Pod管理" class="headerlink" title="【题目7】Pod管理"></a>【题目7】Pod管理</h4><p>在master节点/root目录下编写yaml文件nginx.yaml，具体要求如下：</p>
<p>（1）Pod名称：nginx-pod；</p>
<p>（2）命名空间：default；</p>
<p>（3）容器名称：mynginx；</p>
<p>（4）镜像：nginx；拉取策略：IfNotPresent；</p>
<p>（5）容器端口：80。</p>
<p>完成后使用该yaml文件创建Pod，并提交master节点的用户名、密码和IP到答题框。</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">apiVersion:</span> <span class="string">v1</span></span><br><span class="line"><span class="attr">kind:</span> <span class="string">Pod</span></span><br><span class="line"><span class="attr">metadata:</span></span><br><span class="line">  <span class="attr">name:</span> <span class="string">nginx-pod</span></span><br><span class="line">  <span class="attr">namespace:</span> <span class="string">default</span></span><br><span class="line"><span class="attr">spec:</span></span><br><span class="line">  <span class="attr">containers:</span></span><br><span class="line">    <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">mynginx</span></span><br><span class="line">      <span class="attr">imagePullPolicy:</span> <span class="string">IfNotPresent</span></span><br><span class="line">      <span class="attr">image:</span> <span class="number">192.168</span><span class="number">.10</span><span class="number">.8</span><span class="string">/library/nginx:latest</span></span><br><span class="line">      <span class="attr">ports:</span></span><br><span class="line">        <span class="bullet">-</span> <span class="attr">containerPort:</span> <span class="number">80</span>	</span><br></pre></td></tr></table></figure>



<h4 id="【题目8】Namespace管理"><a href="#【题目8】Namespace管理" class="headerlink" title="【题目8】Namespace管理"></a>【题目8】Namespace管理</h4><p>在master节点/root目录下编写yaml文件my-namespace.yaml，具体要求如下：</p>
<p>（1）Namespace名称：test。</p>
<p>完成后使用该yaml文件创建Namespace，并提交master节点的用户名、密码和IP到答题框。</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">apiVersion:</span> <span class="string">v1</span></span><br><span class="line"><span class="attr">kind:</span> <span class="string">Namespace</span></span><br><span class="line"><span class="attr">metadata:</span></span><br><span class="line">   <span class="attr">name:</span> <span class="string">test</span></span><br></pre></td></tr></table></figure>



<h4 id="【题目9】Deployment管理"><a href="#【题目9】Deployment管理" class="headerlink" title="【题目9】Deployment管理"></a>【题目9】Deployment管理</h4><p>在master节点/root目录下编写yaml文件nginx-deployment.yaml，具体要求如下：</p>
<p>（1）Deployment名称：nginx-deployment；</p>
<p>（2）命名空间：default；</p>
<p>（3）Pod名称：nginx-deployment，副本数：2；</p>
<p>（4）网络：hostNetwork；</p>
<p>（5）镜像：nginx；</p>
<p>（6）容器端口：80</p>
<p>完成后使用该yaml文件创建Deployment，并提交master节点的用户名、密码和IP到答题框。</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">apiVersion:</span> <span class="string">apps/v1</span></span><br><span class="line"><span class="attr">kind:</span> <span class="string">Deployment</span></span><br><span class="line"><span class="attr">metadata:</span></span><br><span class="line">  <span class="attr">name:</span> <span class="string">nginx-deployment</span></span><br><span class="line">  <span class="attr">namespace:</span> <span class="string">default</span></span><br><span class="line">  <span class="attr">labels:</span></span><br><span class="line">    <span class="attr">app:</span> <span class="string">nginx</span></span><br><span class="line"><span class="attr">spec:</span></span><br><span class="line">  <span class="attr">replicas:</span> <span class="number">2</span></span><br><span class="line">  <span class="attr">selector:</span></span><br><span class="line">    <span class="attr">matchLabels:</span></span><br><span class="line">      <span class="attr">app:</span> <span class="string">nginx</span></span><br><span class="line">  <span class="attr">template:</span></span><br><span class="line">    <span class="attr">metadata:</span></span><br><span class="line">      <span class="attr">labels:</span></span><br><span class="line">        <span class="attr">app:</span> <span class="string">nginx</span></span><br><span class="line">    <span class="attr">spec:</span></span><br><span class="line">      <span class="attr">hostNetwork:</span> <span class="literal">true</span></span><br><span class="line">      <span class="attr">containers:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">nginx</span></span><br><span class="line">        <span class="attr">image:</span> <span class="number">192.168</span><span class="number">.10</span><span class="number">.8</span><span class="string">/library/nginx:latest</span></span><br><span class="line">        <span class="attr">ports:</span></span><br><span class="line">        <span class="bullet">-</span> <span class="attr">containerPort:</span> <span class="number">80</span></span><br></pre></td></tr></table></figure>

<h4 id="【题目10】PV管理"><a href="#【题目10】PV管理" class="headerlink" title="【题目10】PV管理"></a>【题目10】PV管理</h4><p>在master节点的/root/目录下编写pv的yaml文件pv.yaml，要求如下：</p>
<p>（1）名字：pv-exam;</p>
<p>（2）类型：HostPath;</p>
<p>（3）路径：/data;</p>
<p>（4）大小：1G;</p>
<p>（5）回收策略：Recycle；</p>
<p>（6）模式：ReadOnlyMany；</p>
<p>完成后使用该yaml文件启动PV，并提交master节点的用户名、密码到IP答题框。</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">apiVersion:</span> <span class="string">v1</span></span><br><span class="line"><span class="attr">kind:</span> <span class="string">PersistentVolume</span></span><br><span class="line"><span class="attr">metadata:</span></span><br><span class="line">  <span class="attr">name:</span> <span class="string">pv-exam</span></span><br><span class="line"><span class="attr">spec:</span></span><br><span class="line">  <span class="attr">capacity:</span></span><br><span class="line">    <span class="attr">storage:</span> <span class="string">1Gi</span></span><br><span class="line">  <span class="attr">accessModes:</span></span><br><span class="line">    <span class="bullet">-</span> <span class="string">ReadOnlyMany</span></span><br><span class="line">  <span class="attr">persistentVolumeReclaimPolicy:</span> <span class="string">Recycle</span></span><br><span class="line">  <span class="attr">hostPath:</span></span><br><span class="line">    <span class="attr">path:</span> <span class="string">/data</span></span><br></pre></td></tr></table></figure>

<h4 id="【题目11】资源配额管理"><a href="#【题目11】资源配额管理" class="headerlink" title="【题目11】资源配额管理"></a>【题目11】资源配额管理</h4><p>在master节点/root/目录下编写Pod的yaml文件memory-request-limit.yaml，要求如下：</p>
<p>（1）命名空间：default；</p>
<p>（2）Pod名称：memory-demo；</p>
<p>（3）镜像：nginx:latest；镜像拉去策略：ifNotPresent；</p>
<p>（4）容器名称：memory-demo；</p>
<p>（5）内存请求为100MIB，并被限制在200MIB以内。</p>
<p>完成后使用该yaml文件启动Pod，并提交master节点的用户名、密码和IP到答题框。</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">apiVersion:</span> <span class="string">v1</span></span><br><span class="line"><span class="attr">kind:</span> <span class="string">Pod</span></span><br><span class="line"><span class="attr">metadata:</span></span><br><span class="line">  <span class="attr">name:</span> <span class="string">memory-demo</span></span><br><span class="line">  <span class="attr">namespace:</span> <span class="string">default</span></span><br><span class="line"><span class="attr">spec:</span></span><br><span class="line">  <span class="attr">containers:</span></span><br><span class="line">    <span class="bullet">-</span> <span class="attr">image:</span> <span class="number">192.168</span><span class="number">.10</span><span class="number">.8</span><span class="string">/library/nginx:latest</span></span><br><span class="line">      <span class="attr">name:</span> <span class="string">nginx</span></span><br><span class="line">      <span class="attr">imagePullPolicy:</span> <span class="string">IfNotPresent</span></span><br><span class="line">      <span class="attr">resources:</span></span><br><span class="line">        <span class="attr">requests:</span></span><br><span class="line">          <span class="attr">memory:</span> <span class="string">100Mi</span></span><br><span class="line">        <span class="attr">limits:</span></span><br><span class="line">          <span class="attr">memory:</span> <span class="string">200Mi</span></span><br></pre></td></tr></table></figure>




        </div>

        
            <section class="post-copyright">
                
                    <p class="copyright-item">
                        <span>Author:</span>
                        <span>John Doe</span>
                    </p>
                
                
                    <p class="copyright-item">
                        <span>Permalink:</span>
                        <span><a href="http://example.com/2022/04/16/k8s%E7%9B%B8%E5%85%B3%E7%BB%83%E4%B9%A0/">http://example.com/2022/04/16/k8s%E7%9B%B8%E5%85%B3%E7%BB%83%E4%B9%A0/</a></span>
                    </p>
                
                
                    <p class="copyright-item">
                        <span>License:</span>
                        <span>Copyright (c) 2022 <a target="_blank" rel="noopener" href="http://qiwensong.top">CC-BY-NC-4.0</a> LICENSE</span>
                    </p>
                
                
                     <p class="copyright-item">
                         <span>Slogan:</span>
                         <span>Do you believe in <strong>DESTINY</strong>?</span>
                     </p>
                

            </section>
        
        <section class="post-tags">
            <div>
                <span>Tag(s):</span>
                <span class="tag">
                    
                    
                        <a href="/tags/cloud/"># cloud</a>
                    
                        
                </span>
            </div>
            <div>
                <a href="javascript:window.history.back();">back</a>
                <span>· </span>
                <a href="/">home</a>
            </div>
        </section>
        <section class="post-nav">
            
                <a class="prev" rel="prev" href="/2022/04/16/email%E4%BB%8B%E7%BB%8D/">email介绍</a>
            
            
            <a class="next" rel="next" href="/2022/04/15/copilot/">Copilot初体验</a>
            
        </section>


    </article>
</div>

            </div>
            <footer id="footer" class="footer">
    <div class="copyright">
        <span>© John Doe | Powered by <a href="https://hexo.io" target="_blank">Hexo</a> & <a href="https://github.com/Siricee/hexo-theme-Chic" target="_blank">Chic</a></span>
    </div>
</footer>

    </div>
</body>

</html>